<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form ref="userForm" :model="userInfo" :rules="rules" label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width:220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间" prop="timeOfEntry">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <!-- <img :src="userInfo.staffPhoto"> -->
        <!-- 可以用$event接受子组件传来的值 -->
        <!-- <upload-img @input="getE($event)" /> -->
        <!-- <upload-img :value="userInfo.staffPhoto" @input="e => userInfo.staffPhoto = e" /> -->
        <upload-img v-model="userInfo.staffPhoto" />

      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="updateUserInfo">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserStaffPhoto } from '@/api/user'
import { updateUseInfo } from '@/api/employees '
export default {
  data() {
    return {
      userId: this.$route.query.id,
      userInfo: {
        mobile: '',
        timeOfEntry: '',
        staffPhoto: ''
      },
      rules: {
        timeOfEntry: [
          { required: true, message: '入职日期不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.loadPeopleInfo()
  },
  methods: {
    async loadPeopleInfo() {
      try {
        const res = await getUserStaffPhoto(this.userId)
        // console.log(res)
        this.userInfo = res.data
      } catch (e) {
        console.log(e)
      }
    },
    async updateUserInfo() {
      this.$refs.userForm.validate(valid => {
        if (!valid) return
        this.doSave()
        this.$router.back()
      })
    },
    async doSave() {
      try {
        const res = await updateUseInfo(this.userInfo)
        // console.log(res)
        this.$message.success(res.message)
      } catch (e) {
        this.$message.error(e.message)
      }
    }
    // getE(e) {
    //   console.log(e)
    // }
  }

}
</script>

<style scoped lang="scss">
  .user-info{
    padding-top:20px;
  }
</style>
